/**
 * 
 */
package com.smarthome.core.area.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.smarthome.base.service.ShAreaCityService;
import com.smarthome.base.service.ShAreaDistrictService;
import com.smarthome.core.area.AreaCityService;
import com.smarthome.domain.bean.ShAreaCity;
import com.smarthome.domain.bean.ShAreaDistrict;

/**
 * @author dhc
 * @date 2015年10月12日 下午5:47:02
 * @title
 */
@Service("areaCityService")
public class AreaCityServiceImpl implements AreaCityService {

	@Resource(name="shAreaCityService")
	private ShAreaCityService areaCityService;

	@Resource(name="shAreaDistrictService")
	private ShAreaDistrictService areaDistrictService;
	
	@Override
	public ShAreaCity queryShAreaCityById(Long id) {
		ShAreaCity city =  areaCityService.selectEntryById(id);
		if(city != null){
			List<ShAreaCity> citys = new ArrayList<ShAreaCity>();
			citys.add(city);
		}
		return city;
	}

	@Override
	public List<ShAreaCity> queryShAreaCitys(ShAreaCity areaCity) {
		List<ShAreaCity> citys = areaCityService.selectEntryList(areaCity);
		return citys;
	}
	
	public void addParam(List<ShAreaCity> citys  ){
		if(null == citys || citys.size() == 0) return ;
		List<ShAreaDistrict> districts = areaDistrictService.selectEntryList(null);
		if(districts != null && districts.size() > 0){
			Map<Long,List<ShAreaDistrict>> map = new HashMap<Long,List<ShAreaDistrict>>();
			for(ShAreaDistrict d : districts){
				List<ShAreaDistrict> ds = map.get(d.getCityId());
				if(ds == null){
					ds = new ArrayList<ShAreaDistrict>();
					map.put(d.getCityId(), ds);
				}
				ds.add(d);
			}
			
			for(ShAreaCity c : citys){
				c.setDistricts(map.get(c.getId()));
			}
			
		}
	}
	

}
